

local crads = {
    '卫宫巨侠',
    'Caster',
    'Assassin',
    'Lancer',
    'Berserker',
    'Rider',
    'Avenger',
    '征服王',
    '英雄王',
    'Saber',
    '红A',
    '圣杯',
    
}

local mt = ac.skill['卫宫巨侠']
function mt:on_card(hero,player)
    if hero[self.name] then
        return
    end
    hero[self.name] = true
    for _,name in ipairs(crads) do
        player:set_data(name,true)
    end

    player:event '卡池-添加卡组'(function(_,_,pool)
        for _,name in ipairs(crads) do
            pool[#pool+1] = name
        end
    end)
    hero:event '天赋-检测合成'(function(trg)
        if hero:find_skill('圣杯') and hero:find_skill('Saber') and hero:get_data('命运-计数',0)>=10 then
            trg:remove()
            for _,temp in ipairs(get_card_list(hero,'命运')) do
                hide_card(temp)
            end
            hero:notify('英雄-获得天赋',hero,'Saber Alter')
        end
    end)
    hero:event '天赋-检测合成后'(function(trg)
        local haves = hero:get_data('拥有天赋表') or {}
        for _,name in ipairs(crads) do
            if not haves[name] then
                return
            end
        end
        trg:remove()
        hero:set_data('完成-计数',hero:get_data('完成-计数',0) + 1)
    end)
end


local mt = ac.skill['贯穿之枪']
function mt:on_add()
    local hero = self.owner
    local count = 0
    self:gc(hero:event '单位-攻击命中'(function(_,_,target)
        if count>=self.data1 then
            count = 0
            local damage = hero:get(self['属性1']) * self.data2 / 100
            hero:create_damage(target,damage,'物理',self)
        end
    end))
    self:gc(hero:event '单位-造成伤害'(function(_,data)
        if data['暴击'] then
            count = count + 1
        end
    end))
end


local mt = ac.skill['骑士不死于徒手']
function mt:on_add()
    local hero = self.owner
    local count = 0
    self:gc(hero:event '单位-击杀'(function(_,_,target)
        hero:add_buff '骑士不死于徒手'{
            art = self.art,
            data1 = self.data1,
            time = self.data2,
            cover_max = self.data3,
        }
    end))
end

local buff = ac.buff['骑士不死于徒手']
buff.tip = [[每层提升'data1'%攻击,上限10层]]
buff.time = 3
buff.stack = 0
buff.data1 = 0

function buff:on_cover()
    local hero = self.owner
    self:set_remaining(self.time)
    if self.stack<10 then
        self:on_add()
    end
    return false
end
function buff:on_add()
    self.stack = self.stack + 1
    self:gc(self.owner:add('攻击加成',self.data1))
end


local mt = ac.skill['自我封印·鲜血神殿']
mt.model1 = [[634b489d5f0ec8b2cbb20e8064de6733.mdl]]
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-造成伤害'(function(_,data)
        if data['暴击'] and self:is_cooling()==false then
            self:cooling()
            local damage = data.real_damage * self.data1 / 100
            local point = data.target:get_point()
            point:add_effect(self.model1):remove()
            for u in ac.selector('unit')
                : range(data.target,300)
                : enemy(hero)
                : loop()
            do
                u:damage{
                    source = hero,
                    skill = self,
                    damage = damage,
                    ['附加'] = true,
                }
            end
            
        end
    end))
end


local mt = ac.skill['此世之恶']
function mt:on_card(hero,player)
    local count = 0
    self:gc(ac.loop(100,function()
        local num = math.ceil((100 - hero:get('当前生命百分比'))/self.data1) * self.data2
        hero:add('暴击伤害',num - count)
        count = num
    end))
    self:gc(function()
        hero:add('暴击伤害', - count)
    end)
end



local mt = ac.skill['王之军势']
mt.temp = '攻击计数'
mt.count = 12
mt.distance = 1800
mt.missile_art = [[cb98001f7cb8007e6313ef0dbf2ee16c.mdl]]

function mt:on_init(hero)
    self.count = self.data1
end

function mt:on_run(hero,target)
    local hero = self.owner
    local point1 = hero:get_point()
    local point2 = target:get_point()
    local angle = point1/point2
    local point3 = point1 - {angle,-450}
    local num = 6
    local group = {}
    local damage = hero:get(self['属性1']) * self.data2 / 100
    for a=1,num do
        local dis = (a-num/2 -0.5) * 100
        local point = point3 - {angle+90,dis}
        local mover = point:launch_wave(self.missile_art,angle,900,self.distance)
        local track = hero:track_select(mover,150,mover.distance/mover.speed,function(u)
            if not group[u.handle] then
                group[u.handle] = true
                hero:create_damage(u,damage,self)
            end
        end)
    end
end




local mt = ac.skill['王之财宝']
mt.model1 = [[ac72ed77c0b82937d1d2b04a5fda91b6.mdl]]
mt.missile_art = [[edcc5ae7d44d9f4dacc91d74dfc7d03b.mdl]]
function mt:on_add()
    local hero = self.owner
    self:gc(ac.loop(self.data1*1000,function()
        if hero:is_alive() then
            local target = target or ac.selector('unit'):range(hero,900):enemy(hero):random()
            if target then
                local damage = hero:get('攻击') * self.data3 / 100
                hero:notify('触发-天地乖离',hero,target)
                hero:launch_missile(target,self.missile_art,2800,0,function()
                    hero:create_damage(target,damage,self)
                end)
            end
        end
    end))
end



local mt = ac.skill['天地乖离']
mt.model1 = [[ac72ed77c0b82937d1d2b04a5fda91b6.mdl]]
function mt:on_add()
    local hero = self.owner
    local count = 0
    self:gc(hero:add_buff(self.name){
        art = self.art,
        tip = self:get_tip(),
        keep = true,
        on_add = function(buff)
            buff:gc(hero:event '触发-天地乖离'(function(_,_,target)
                count = count + 1
                buff.stack = count
                if count>=self.data1 then
                    count = 0
                    local damage = hero:get('攻击') * self.data2 / 100
                    local point = hero:get_point()
                    local angle = point / target:get_point()
                    point:effect{
                        model = self.model1,
                        angle = angle,
                        size = 0.5,
                        time = 3,
                    }
                    ac.timer(100,30,function()
                        hero:line_damage(point,angle,900,200,damage/30,self)
                    end)
                end
            end))
        end
    })
end

local mt = ac.skill['咖喱棒']

mt.model1 = [[670729cf6ea109eed8dca2bc449fe4c8.mdl]]

function mt:on_add()
    local hero = self.owner
    self:gc(ac.loop(self.data1 * 1000,function()
        if not hero:is_alive() then
            return
        end
        local point = hero:get_point()
        local angle = point / target:get_point()
        local damage = hero:get(self['属性1']) * self.data2 / 100
        point:effect{
            model = self.model1,
            angle = angle,
            time = 0.1,
        }
        hero:line_damage(point,angle,2500,300,damage,self)
    end))
end


function mt:on_run(target)
    target:add_effect(self.model1):remove()
end

local mt = ac.skill['无限剑制']
mt.model1 = [[9bd6fde600075ca24816da0b250b52f3.mdl]]

function mt:on_add()
    local hero = self.owner
    self:gc(ac.loop(self.data1 * 1000,function()
        if not hero:is_alive() then
            return
        end
        ac.timer(1000,5,function()
            local damage = hero:get(self['属性1']) * self.data3 / 100
            local group = ac.selector('unit'):range(hero,self.data2):enemy(hero):get()
            for a,u in ipairs(group) do
                ac.wait(100*a,function()
                    u:add_effect(self.model1):remove()
                    hero:create_damage(u,damage,self)
                end)
            end
        end)
    end))
end



local mt = ac.skill['吞噬命运']

function mt:on_add()
    local hero = self.owner
    for _,temp in ipairs(get_card_list(hero,'命运')) do
        hide_card(temp)
    end
    self:gc(hero:event '英雄-抽卡完毕'(function(_,_,skill)
        if skill.name~=self.owner_skill.name and skill.card_class1['命运'] and skill['品质']~='UR' and skill['品质']~='UR+' then
            hide_card(skill)
        end
    end))
end

local mt = ac.skill['天之杯']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:add_buff(self.name){
        art = self.art,
        tip = self:get_tip(),
        keep = true,
        pulse = 5,
        not_show_pulse = 1,
        num = 0,
        on_pulse = function(buff)
            local count = (ac.player.online_count - 1)
            hero:add('暴击几率',count * self.data1 - buff.num)
            buff.num = count
        end,
        on_remove = function(buff)
            hero:add('暴击几率', - buff.num)
        end,
    })
end



local mt = ac.skill['誓约·漆黑']
mt.temp = '攻击触发'
mt.odds = 20
function mt:on_init()
    self.odds = self.data1
end
function mt:on_run(hero,target)
    local hero = self.owner
    hero:add_buff '魔力暴走'{
        art = self.art,
        data1 = self.data2,
        data2 = self.data3,
        time = self.data4,
    }
end

local buff = ac.buff['魔力暴走']
mt.data1 = 0
mt.data2 = 0
mt.model1 = [[6e5229cb6fab54e0b856eac2355e0818.mdl]]
mt.tip = [[提升伤害增幅，但是也会受到额外伤害]]

function buff:on_add()
    local hero = self.owner
    self:gc(hero:add_effect(self.model1,'overhead'))
    self:gc(hero:add('伤害增幅',self.data1))
    self:gc(hero:event '单位-受到伤害前'(function(_,_,_,data)
        data:mul(self.data2)
    end))
end

local mt = ac.skill['EXCALIBUR MORGAN']
mt.model1 = [[edac76db6bbac156fa4273bfca392101.mdl]]

function mt:on_add()
    local hero = self.owner
    local cool = 0
    self:gc(hero:event '单位-攻击命中'(function(_,_,target)
        if hero:get('当前生命百分比')<=self.data1 and cool<ac.clock() then
            cool = ac.clock() + 30*1000
            local damage = hero:get(self['属性2']) * self.data2 / 100 + (hero:get('生命上限') - hero:get('生命')) * self.data3 / 100
            local point = hero:get_point()
            local angle = point / target:get_point()
            point:effect{
                model = self.model1,
                angle = angle,
                time = 1,
            }
            hero:line_damage(point,angle,2500,300,damage,self)
        end
    end))
end
